package com.example.spingbootvue.service;

import com.example.spingbootvue.entity.User;
import com.example.spingbootvue.mapper.UserMapper;
import com.example.spingbootvue.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class loginservice {

    @Autowired
    UserMapper userMapper;

    public User logintest(User user){
    User users= userMapper.selectnameandpassword(user.getAccount(),user.getPassword());

        System.out.println(users);
    if(users==null){
        return null;//账号密码在数据库查询不到返回空账号密码错误
    }else {
        //生成token
        String token = TokenUtils.createtoken(users.getId().toString(),users.getPassword());
        users.setToken(token);
        return users;
    }
    }
}
